'''固定代码'''
# 导包
import urllib3


# 没有继承,可以不用加括号
class LoginApi:
    # 初始化
    def __init__(self):
        # 1.忽略警告--去除很多报错
        urllib3.disable_warnings()
        # 验证码url
        self.url_verify = "http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=verify"
        # 登录url
        self.url_login = "https://demo6.tp-shop.cn/index.php?m=Home&c=User&a=do_login"

    # 获取验证码
    def get_verify_code(self, session):
        response = session.get(self.url_verify, verify=False)
        # with open("../data/code.png", "wb") as f:
        #     f.write(response.content)
        # code = input('请输入验证码：')

        # return response, code
        return response

    # 登录
    def login(self, session, username, password, verify_code):
        login_data = {
            'username': username,
            'password': password,
            'verify_code': verify_code
        }
        response = session.post(url=self.url_login, data=login_data, verify=False)

        return response
